@include('admin.layout.bone_header')

<div class="layui-form layui-form-pane search">

    <div class="layui-form-item">


        <label class="layui-form-label">会员ID</label>
        <div class="layui-input-inline">
            <input type="text" id="user_id" autocomplete="off" placeholder="请输入会员ID" class="layui-input">
        </div>

        <label class="layui-form-label">商品标题</label>
        <div class="layui-input-inline">
            <input type="text" id="goods_title" autocomplete="off" placeholder="请输入商品标题" class="layui-input">
        </div>
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" autocomplete="off" id="start_time" placeholder="开始时间" lay-key="1">
        </div>


    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" autocomplete="off" id="end_time" placeholder="结束时间" lay-key="2">
        </div>
        <button class="layui-btn" data-type="reload">搜索</button>
        <button class="layui-btn" data-type="export">导出</button>
    </div>
</div>

<div style="display: none">
    <table id="score">

    </table>
</div>
<table class="layui-hide" id="think-table" lay-filter="think-table"></table>

<script type="text/html" id="barDemo">

    @{{# if(d['status'] == 1){ }}
    <a class="layui-btn layui-btn-xs" lay-event="send_huo">发货</a>
    @{{# } }}
{{--    <a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>--}}


</script>

<script>
    let dd;
    layui.use(['table','laydate'], function () {
        let table = layui.table,
            laydate = layui.laydate,
            tableB = layui.table;



        laydate.render({
            elem: '#start_time'
        });

        laydate.render({
            elem: '#end_time'
        });
        UI.getPageTable(table, "{{route('admin.orders.orders')}}", [
            {field: 'order_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
            , {field: 'user_id',width: 100, title: ' 用户'}
            , {field: 'order_json_data_oo',width: 150, title: ' 商品名称',templet:function (d){
                    let  data = JSON.parse(d['order_json_data']);
                    console.log(JSON.parse(d['order_json_data']))
                    return data['goods_name'];
                }}
            , {field: 'orders_code',width: 200, title: ' 订单号'}
            , {field: 'price',width: 200, title: ' 支付金额'}
            , {field: 'pay_type',width: 200, title: ' 支付类型',templet:function (d){
                let arr = ['未知','微信支付','余额支付']
                    return arr[d['pay_type']]
                }}
            , {field: 'address',width: 350, title: ' 地址',templet:function (d){
                let json_data = JSON.parse(d['address_json_data']);
                return json_data['address_name']+'-'+json_data['address_phone']+'-'+json_data['address_details_str']
            }}
            , {field: 'status',width: 100, title: ' 状态',templet:function (d){
                    let arr = ['未支付','已支付','待收货','已完成'];
                    return arr[d['status']]
                }}
            , {field: 'status',width: 180, title: ' 创建时间',templet:function (d){
                    return Utils.paraseTime(d['created_at'])
                }}
            ,{fixed: 'right',title:'操作',width: 100, align:'center', toolbar: '#barDemo'}
        ]);

        table.on('tool(think-table)', function (obj) {
            let data = obj.data;
            if(obj.event === 'send_huo'){
                UI.openLayer('{{route('admin.orders.send_huo')}}?order_id='+data['order_id']);
            }
        });
        let $ = layui.$, active = {
            reload:function (){
                let user_id = $('#user_id');
                let goods_title = $('#goods_title');
                let start_time = $('#start_time');
                let end_time = $('#end_time');
                //执行重载
                table.reload('think-table', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        'user_id':user_id.val(),
                        'goods_title_like':goods_title.val(),
                        'start_time':start_time.val(),
                        'end_time':end_time.val(),
                    }
                });
            },
            export:function (){
                let user_id = $('#user_id');
                let goods_title = $('#goods_title');
                let start_time = $('#start_time');
                let end_time = $('#end_time');
                HttpUtils.get('{{route('admin.orders.orders_no_page')}}',{
                    'user_id':user_id.val(),
                    'goods_title_like':goods_title.val(),
                    'start_time':start_time.val(),
                    'end_time':end_time.val(),
                },function (res){

                     dd = tableB.render({
                        elem: '#score'//获取标签
                        , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
                        , title: '订单导出'//导出数据excel的表名称
                        , height: 'full-140'  //高度设置
                        , limit: 2
                        , cols: [[
                            {field: 'order_id', title: 'ID', width: 80, sort: true, fixed: 'left'}
                            , {field: 'user_id',width: 100, title: ' 用户'}
                            , {field: 'goods_name',width: 150, title: ' 商品名称'}
                            , {field: 'orders_code',width: 200, title: ' 订单号'}
                            , {field: 'price',width: 200, title: ' 支付金额'}
                            , {field: 'pay_str',width: 200, title: ' 支付类型'}
                            , {field: 'max_recive',width: 100, title: ' 最大收益'}
                            , {field: 'order_send_max_recive',width: 100, title: ' 剩余收益'}
                            , {field: 'order_send_score',width: 100, title: ' 预计金币'}
                            , {field: 'order_send_score_jingtai',width: 100, title: ' 静态金币'}
                            , {field: 'order_send_score_recive',width: 150, title: ' 静态剩余金币'}
                            , {field: 'address_str',width: 350, title: ' 地址'}
                            , {field: 'status_str',width: 100, title: ' 状态'}
                            , {field: 'created_at_str', title: ' 创建时间'}
                            ,{fixed: 'right',title:'操作',width: 100, align:'center', toolbar: '#barDemo'}
                        ]]
                        , data: res.data
                        , done: function (res) {
                        }
                    });


                    tableB.exportFile(dd.config.id, res.data, 'xls');

                });
            }
        };
        $('.layui-btn-container .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        $('.search .layui-btn').on('click', function () {
            let type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    })


</script>


@include('admin.layout.bone_footer')
